home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
VideoToolbox 96.06.15
/
(Demos)
/
Quitter.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-10
|
4KB
|
82 lines
/*
Quitter.c
Kill a program on a local or remote computer by sending an AppleEvent.
Unfortunately, it appears that Apple doesn't consider active desk accessories as
"processes" to which one can send an AppleEvent. The notes in KillEveryoneButMe.c
indicate that the Finder can help out the AppleEvents mechanism for applications
(and desk accessories?) that aren't apple-event aware by using "puppet strings".
However, the KillEveryoneButMe.c notes indicate that puppet strings are only
available if one identifies the target by Process Serial Number (PSN), i.e. one
uses the typeProcessSerialNumber descriptor type, but the documentation of
"Specifying a Target Address" in THINK Reference says that "to address an Apple
event to a target on a remote computer on the network you must use either the
typeSessionID or the typeTargetID descriptor type." Thus, to use puppet string we
MUST use the PSN, but if the target is on a remote computer we CAN'T use the PSN.
So apparently we can't use puppet strings on a remote computer.
At present this has nothing at all to do with the rest of the VideoToolbox, but
David Brainard and I have been discussing the idea of a stand-alone VideoToolbox
application that accepts AppleEvents commanding it to produce visual stimuli.
NOTE:
It is essential that the isHighLevelEventAware bit be set in your application's SIZE resource,
otherwise all your attempts to emit apple events will be ignored.
In CodeWarrior, use the Edit:Preferences menu item to set the Project:SIZE Flags.
In THINK C, use the menu item Project:SetProjectType:SIZE Flags.
SEE ALSO:
VideoToolboxSources:KillEveryoneButMe.c.
HISTORY:
3/5/93 dgp wrote it
3/9/93 dgp got it to work, by setting the HighLevelEvent-Aware bit, as instructed
by Larry Harris, 76150,1027, a friendly fellow programmer on CompuServe.
4/17/93 dgp #include VideoToolbox.h for PrintfExit().
12/15/93 dgp Go away quietly if user hits Cancel.
7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
Metrowerks CodeWarrior C.
9/5/94 dgp removed assumption in printf's that int==short.
6/10/95 dgp added discussion of puppetstrings above.
*/
#include "VideoToolbox.h"
#include <stdio.h>
#include <AppleEvents.h>
void main(void)
{
int error;
unsigned char prompt[]="\pChoose a program to quit.";
PortInfoRec portInfo;
TargetID targetID;
AEAddressDesc target;
AppleEvent appleEvent;
AESendMode sendMode;
long value;
MaximizeConsoleHeight();
printf("Welcome to Quitter.\n");
error=Gestalt(gestaltAppleEventsAttr,&value);
if(error || !(value&(1<<gestaltAppleEventsPresent)))PrintfExit("Sorry, I need AppleEvents.\n");
PPCInit();
// Select target through dialog with user.
error=PPCBrowser(prompt,NULL,0,&targetID.location,&portInfo,NULL,NULL);
if(error==-128)abort(); // User pressed Cancel.
if(error)PrintfExit("PPCBrowser error %d\n",error);
targetID.name=portInfo.name;
error=AECreateDesc(typeTargetID,(Ptr)&targetID,sizeof(targetID),&target);
if(error)PrintfExit("AECreateDesc error %d\n",error);
error=AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&target
,kAutoGenerateReturnID,kAnyTransactionID,&appleEvent);
if(error)PrintfExit("AECreateAppleEvent error %d\n",error);
error=AEDisposeDesc(&target);
sendMode=kAENoReply+kAENeverInteract+kAEDontReconnect;
error=AESend(&appleEvent,NULL,sendMode,kAENormalPriority
,kAEDefaultTimeout,NULL,NULL);
if(error)PrintfExit("AESend error %d\n",error);
error=AEDisposeDesc(&appleEvent);
if(error)PrintfExit("AEDisposeDesc error %d\n",error);
printf("Done. “%s” has been asked to quit.\n",p2cstr(targetID.name.name));
}